public class time_20250411_DiagonalSum {
    public static int diagonalSum(int[][] matrix){//传参传入一个二维数组
        int sum = 0;
        int n = matrix.length;
        for(int i = 0;i < n;i++){
            sum += matrix[i][i];//对角线元素相加
        }
        return sum;
    }
    public static void main(String[] args){
        int[][] matrix = {
                {1,2,3}, {4, 5, 6},{7,8,9}
        };
        System.out.println("对角线元素和为："+diagonalSum(matrix));
    }
}




